package com.start.handler;

import java.util.Date;
import java.util.Map;

import org.apache.catalina.ant.SessionsTask;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;

import com.start.bean.User2;

@Controller
@SessionAttributes(value = { "abc" })
public class Anno {
	// ****************
	@RequestMapping("/setSessionAttribute")
	public String setSessionAttribute(Model model) {
		model.addAttribute("abc", "李四");
		return "success";
	}

	@RequestMapping("/getSessionAttribute")
	public String getSessionAttribute(ModelMap modelMap) {
		Object object = modelMap.get("abc");
		System.out.println("Anno.getSessionAttribute()" + object);
		return "success";
	}

	@RequestMapping("/delSessionAttribute")
	public String delSessionAttribute(SessionStatus status) {
		status.setComplete();
		System.out.println("Anno.delSessionAttribute()---");
		return "success";
	}

	
	
	// ******************
	@RequestMapping("/getModelAttribute2")
	public String getModelAttribute2(@ModelAttribute("abc") User2 user2) {
		System.out.println("执行了>>>>>>");
		System.out.println("Anno.getModelAttribute()>>>>>>" + user2);
		return "success";
	}

	// @ModelAttribute
	public void getModelAttributeModelAttribute2(String uname, Map<String, User2> map) {
		User2 user2 = new User2();
		user2.setUname(uname);
		user2.setAge(20);
		user2.setDate(new Date());
		map.put("abc", user2);
	}

	@RequestMapping("/getModelAttribute")
	public String getModelAttribute(User2 user2) {
		System.out.println("执行了>>>>>>");
		System.out.println("Anno.getModelAttribute()>>>>>>" + user2);
		return "success";
	}

	// @ModelAttribute
	public User2 getModelAttributeModelAttribute(String uname) {
		User2 user2 = new User2();
		user2.setUname(uname);
		user2.setAge(20);
		user2.setDate(new Date());
		System.out.println("Anno.u()" + ">>>>" + user2);
		return user2;
	}

	// *********************
	@RequestMapping("/getCookieValue")
	public String getCookieValue(@CookieValue("JSESSIONID") String name) {
		System.out.println("执行了>>>>>>");
		System.out.println("Anno.getCookieValue()>>>>>>" + name);
		return "success";
	}

	// **********************
	@RequestMapping("/getRequestHeader")
	public String getRequestHeader(@RequestHeader("Accept") String name) {
		System.out.println("执行了>>>>>>");
		System.out.println("Anno.getRequestHeader()>>>>>>" + name);
		return "success";
	}

	// *****************
	@RequestMapping("/getPathVariable/{id}")
	public String getPathVariable(@PathVariable("id") String name) {
		System.out.println("执行了>>>>>>");
		System.out.println("Anno.getPathVariable()>>>>>>" + name);
		return "success";
	}

	// ********************
	@RequestMapping("/getRequestParam")
	public String getRequestParam(@RequestParam("username") String name) {
		System.out.println("执行了>>>>>>");
		System.out.println("Anno.getRequestParam()" + name);
		return "success";
	}

	// ****************
	@RequestMapping("/getRequestBody")
	public String getRequestBody(@RequestBody String body) {
		System.out.println("执行了>>>>>>");
		System.out.println("Anno.getRequestBody()>>>>>>" + body);
		return "success";
	}

}
